//
//  FKVerificationCodeVC.m
//  WanTao
//
//  Created by Macbook Pro on 2019/4/2.
//  Copyright © 2019 Macbook Pro. All rights reserved.
//

#import "FKVerificationCodeVC.h"

@interface FKVerificationCodeVC ()

@property (weak, nonatomic) IBOutlet UILabel *goodNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *codeLabel;
@property (weak, nonatomic) IBOutlet UIImageView *qrcodeImageView;
@property (weak, nonatomic) IBOutlet UILabel *codeTitleLabel;

@property (weak, nonatomic) IBOutlet UILabel *orderSnLabel;
@property (weak, nonatomic) IBOutlet UILabel *mobileLabel;
@property (weak, nonatomic) IBOutlet UILabel *payTimeLabel;
@property (weak, nonatomic) IBOutlet UILabel *numLabel;
@property (weak, nonatomic) IBOutlet UILabel *goodsPriceLabel;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;

@property (nonatomic, assign) CGFloat topCellH;

@end

@implementation FKVerificationCodeVC

- (instancetype)init
{
    return [UIStoryboard storyboardWithName:@"FKVerificationCodeVC" bundle:nil].instantiateInitialViewController;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.qrcodeImageView.hidden = true;
    self.codeTitleLabel.hidden = true;
    self.codeLabel.hidden = true;
    
    self.topCellH = 138;
    
    [self loadData];
}

#pragma mark - Table view data source
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return self.topCellH;
    }
    return 207;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 10;
    }
    return 0.01;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 10;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return nil;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return nil;
}

#pragma mark - 网络请求
- (void)loadData
{
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"order_goods_id"] = self.order_goods_id;
    [FKHttpTool postWithSuffix:@"m=Home&c=OrderList&a=write_off_code" param:param success:^(FKBaseResult *result) {
        if (result.isSuccess) {
            NSDictionary *info = result.data[@"info"];
            if ([info[@"hx_type"] isEqualToString:@"1"]) { // 显示二维码
                self.qrcodeImageView.hidden = false;
                self.codeTitleLabel.hidden = false;
                self.topCellH = 280;
                CGFloat imageWH = 155;
                UIImage *codeImage = [UIImage fk_imageGenerateQRCode:info[@"verify_code"] width:imageWH height:imageWH];
                self.qrcodeImageView.image = codeImage;
            } else {
                self.codeLabel.hidden = false;
                self.topCellH = 138;
            }
            
            self.goodNameLabel.text = info[@"item_title"];
            self.codeLabel.text = fkFORMAT(@"核销码: %@", info[@"verify_code"]);
            
            self.orderSnLabel.text = info[@"order_sn"];
            self.mobileLabel.text = info[@"mobile"];
            self.payTimeLabel.text = [info[@"pay_time"] fk_time];
            self.numLabel.text = info[@"num"];
            self.goodsPriceLabel.text = info[@"goods_price"];
            self.priceLabel.text = info[@"settle_price"];
            
            [self.tableView reloadData];
        }
    } failure:nil];
}

@end
